package com.itheima.jdbc;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
public class JdbcTemplateTest {
    public static void main(String[] arg){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("com/itheima/jdbc/applicationContext.xml");
        JdbcTemplate jdTemplate=(JdbcTemplate) applicationContext.getBean("jdbcTemplate");
        jdTemplate.execute("create table account("+
                "id int primary key auto_increment ,"+
                "username varchar (50),"+
                "balance double)");
        System.out.println("账户表创建成功！");
        AccountDao accountDao=(AccountDao) applicationContext.getBean("accountDao");
        Account account=new Account();
        account.setUsername("Tom");
        account.setBanance(1000.00);;
        int num=accountDao.addAccount(account);
        if (num>0){
            System.out.println("成功插入了"+num+"条数据");
        }else {
            System.out.println("插入操作执行失败");
        }
    }

}
